#!/usr/bin/env python
#-*- coding:utf8 -*-
import web
import json
from vendor.system.controller import ActionController
from app.helpers.application_helper import Helper
class ApplicationController(ActionController):
    def initialize(self):
        self._load_init()

    #初始化参数
    def _load_init(self):
        self.session= web.ctx.session
        self.login  = self.session.login
        self.mid    = 0
        self.user   = object
        if self.login is True:
            self.mid = self.session.mid
            self.user= self.session.user
        self.data['login']  = self.session.login
        self.data['mid']    = self.mid
        self.data['user']   = self.user

    #定义json输出
    def render_json(self,_dict):
        web.header('Content-Type','application/json; charset=utf-8')
        data = {'status' : False }
        data = dict(data,**_dict)
        return json.dumps(data)

    #判断是否登陆
    def require_login(self):
        if self.login is False:
            raise web.seeother('/account/sign_in')

    #判断是否为管理员
    def is_admin(self):
        if self.user.is_admin == 0:
            raise web.seeother('/')
